package com.allenlee.mvphelper.util;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.ScaleAnimation;

import com.qmuiteam.qmui.util.QMUIViewHelper;

/**
 * @author : lifei
 * 创建时间： 19-12-21
 * 更改时间： 19-12-21
 * Email : allen.lee723@qq.com
 * @version :
 * Description： 继承 QMUIViewHelper， 对其做一些补充
 */
public class MHViewHelper extends QMUIViewHelper {

    /**
     * <p>对 View 做缩放变化的进场动画。</p>
     * @param view 做动画的 View
     * @param duration 动画时长(毫秒)
     * @param listener 动画回调
     * @param isNeedAnimation 是否需要动画
     */
    public static ScaleAnimation scaleIn(View view, int duration, Animation.AnimationListener listener, boolean isNeedAnimation) {
        if (view == null) {
            return null;
        }
        if (isNeedAnimation) {
            view.setVisibility(View.VISIBLE);
            ScaleAnimation scale = new ScaleAnimation(0, 1, 0, 1);
            scale.setInterpolator(new DecelerateInterpolator());
            scale.setDuration(duration);
            scale.setFillAfter(true);
            scale.setRepeatCount(0);
            if (listener != null) {
                scale.setAnimationListener(listener);
            }
            view.startAnimation(scale);
            return scale;
        } else {
            view.clearAnimation();
            view.setVisibility(View.VISIBLE);
            return null;
        }
    }
}